<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的积分</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>

</head>
<body class="bg-eee">
    <header class="header">
        <div class="backPrevPage on" onclick="historyBack()"></div>
        <div class="pageTitle">我的积分</div>

    </header>
    <section class="integralPage HTML_BOX">
        <div class="integralTotal">
            <div class="integralBg">
                <img src="../image/integral_bg.png" />
            </div>
            <div class="integralCount">
                    <div class="CountBox">
                        <span>可用积分</span>
                        <span class="intergral"></span>
                        <span onclick="gocou()" class="intBtn">积分兑换</span>
                    </div>
            </div>
        </div>
        <div class="intergralPageTit displayFlex plr">
            <div id="details_title">积分明细</div>
            <div>

            </div>
        </div>
        <ul class="intergralClass">
            <li class="on">全部</li>
            <li>收入</li>
            <li>支出</li>
        </ul>
        <ul class="intergralList plr bg-fff">
            <!-- <li class="displayFlex ">
                <div>
                    <div class="itit">兑换优惠券</div>
                    <div class="time">2018-7-29  15:00</div>
                </div>
                <div class="intergralDetails">-900</div>
            </li>
            <li class="displayFlex bg-fff">
                <div>
                    <div class="itit">兑换优惠券</div>
                    <div class="time">2018-7-29  15:00</div>
                </div>
                <div class="intergralDetails">+2000</div>
            </li> -->
        </ul>
        
        <div class="pageHide dn">暂无数据..</div>
    </section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var type = 0;
    var page = 1;
    var score = 0;
    var ifpage = true;
    $(function(){
        $(".integralTotal").height($(".integralBg").height());
    })
    $(".intergralClass li").click(function(){
        $(".intergralClass li").removeClass("on");
        $(this).addClass("on");
        console.log(type = $(this).index());
        page =1;
        var ifpage = true;
        ready();

    })
    apiready = function(){
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        api.addEventListener({
            name: 'scrolltobottom',
            extra: {
                 threshold: 10
            }
         }, function(ret, err) {
             //页码+1，继续请求数据
             
             if(ifpage){
                page++;
                ready();
             }
        });
        //选择国家后回调
        api.addEventListener({
            name: 'duihuanyhq'
        }, function(ret, err) {
           ready();
        });
        ifCnAndEn();
        ready();
    };
    $(".getPage").click(function(){
        page++;
        ready();
    })
    function ready(){
        pop.loading();
        getAjax(Interface.member_score,{token:token,type:type,page:page},function(res){
            pop.close();
            console.log(JSON.stringify(res));
            var list = res.data.data;
            score = res.data.member_score;
            $(".intergral").html(res.data.member_score);
            if(page==1){
                $(".intergralList").empty();
            }
            if(list!="" && list !=null && list !=false){
                $(".pageHide").addClass("dn");ifpage=true;
                $.each(list,function(i,item){
                    if(cnen==2){
                        item.remark = item.egremark;
                    }
                    var price="";
                    if(item.type==1){
                        price ="+"+item.score;
                    }else{
                        price ="-"+item.score;
                    }

                    var html = '<li class="displayFlex"><div>';
                        html+='<div class="itit">'+item.remark+'</div>';
                        html+='<div class="time">'+timestampToTime(item.create_time)+'</div>';
                    html+='</div><div class="intergralDetails">'+price+'</div></li>';
                      $(".intergralList").append(html);
                })
                if(list.length<10){
                    $(".getPage").hide();
                }
            }else{
                if(page==1){$(".pageHide").removeClass("dn");}ifpage=false;
            }
        },function(res,err){})
    }

    function gocou(){

        openWin('member_intergral_coupon','member_intergral_coupon.html',{score:score})
    }

function timestampToTime(timestamp) {
        //时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var date = new Date(timestamp * 1000);
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' '
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds();
        return Y+M+D+h+m+s;
    }
</script>
<script type="text/javascript">
    function ifCnAndEn(){
        if(cnen==2){
            $(".pageTitle").html('My Points Balance');
            $(".CountBox span").eq(0).html('Available integral');
            $(".CountBox span").eq(2).html('Exchange');
            $("#details_title").html('Details');
            $(".intergralClass li").eq(0).html('All');
            $(".intergralClass li").eq(1).html('Income');
            $(".intergralClass li").eq(2).html('Pay');
            $(".getPage").html('Click to load more...');
        }
    }
</script>
</html>
